package com.dream.vo.stock;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;

import com.dream.model.stock.ProductPartRequest;
import com.dream.model.stock.ProductPartRequest.RequestStatus;
import com.dream.model.stock.ProductPartRequest.StockDirection;
import com.dream.model.stock.ProductPartStock.StockProductType;
import com.dream.utils.date.DateParseUtils;
import com.dream.vo.base.QueryVO;
import com.google.common.collect.Lists;

public class ProductPartStockVO extends QueryVO implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8331477247353885182L;
	
	private String stockType;
	
	private String shopId;

	private String fromShopId;
	
	private String toShopId;
	
	private String productPartId;
	
	private String productPartName;
	
	private String requestType;
	
	private String requestCommont;
	
	private String requestDate;
	
	private String requestUser;
	
	private String manualId;
	
	private String[] requestItemProductPartId;
	
	private Integer[] requestItemNum;
	
	private String[] requestItemComment;
	
	private List<RequestStatus> status;
	
	private List<String> myShops;
	
	private String firstOrg;
	
	private String secondOrg;
	
	private Collection<Long> orgs = Lists.newArrayList();
	
	
	public String getShopId() {
		return shopId;
	}

	public void setShopId(String shopId) {
		this.shopId = shopId;
	}

	public Collection<Long> getOrgs() {
		return orgs;
	}

	public void setOrgs(Collection<Long> orgs) {
		this.orgs = orgs;
	}

	public String getFirstOrg() {
		return firstOrg;
	}

	public void setFirstOrg(String firstOrg) {
		this.firstOrg = firstOrg;
	}

	public String getSecondOrg() {
		return secondOrg;
	}

	public void setSecondOrg(String secondOrg) {
		this.secondOrg = secondOrg;
	}

	public List<String> getMyShops() {
		return myShops;
	}

	public void setMyShops(List<String> myShops) {
		this.myShops = myShops;
	}

	public List<RequestStatus> getStatus() {
		return status;
	}

	public void setStatus(List<RequestStatus> status) {
		this.status = status;
	}

	public String getManualId() {
		return manualId;
	}

	public void setManualId(String manualId) {
		this.manualId = manualId;
	}

	public String getRequestCommont() {
		return requestCommont;
	}

	public void setRequestCommont(String requestCommont) {
		this.requestCommont = requestCommont;
	}

	public String getRequestDate() {
		return requestDate;
	}

	public void setRequestDate(String requestDate) {
		this.requestDate = requestDate;
	}

	public String getRequestUser() {
		return requestUser;
	}

	public void setRequestUser(String requestUser) {
		this.requestUser = requestUser;
	}

	public String[] getRequestItemProductPartId() {
		return requestItemProductPartId;
	}

	public void setRequestItemProductPartId(String[] requestItemProductPartId) {
		this.requestItemProductPartId = requestItemProductPartId;
	}

	public Integer[] getRequestItemNum() {
		return requestItemNum;
	}

	public void setRequestItemNum(Integer[] requestItemNum) {
		this.requestItemNum = requestItemNum;
	}

	public String[] getRequestItemComment() {
		return requestItemComment;
	}

	public void setRequestItemComment(String[] requestItemComment) {
		this.requestItemComment = requestItemComment;
	}

	public String getRequestType() {
		return requestType;
	}

	public void setRequestType(String requestType) {
		this.requestType = requestType;
	}

	public String getStockType() {
		return stockType;
	}

	public void setStockType(String stockType) {
		this.stockType = stockType;
	}

	public String getFromShopId() {
		return fromShopId;
	}

	public void setFromShopId(String fromShopId) {
		this.fromShopId = fromShopId;
	}

	public String getToShopId() {
		return toShopId;
	}

	public void setToShopId(String toShopId) {
		this.toShopId = toShopId;
	}

	public String getProductPartId() {
		return productPartId;
	}

	public void setProductPartId(String productPartId) {
		this.productPartId = productPartId;
	}

	public String getProductPartName() {
		return productPartName;
	}

	public void setProductPartName(String productPartName) {
		this.productPartName = productPartName;
	}
	
	public List<ProductPartRequest> populate(String user){
		
		List<ProductPartRequest> li = Lists.newArrayList();
		if(ArrayUtils.isNotEmpty(requestItemProductPartId)){
			int i=0;
			for(String   id: requestItemProductPartId){
				ProductPartRequest  req = new ProductPartRequest();
				li.add(req);
				
				req.setProductPartId(id);
				
				if(i< requestItemComment.length){
					req.setRequestItemComment(this.requestItemComment[i]);
				}
				req.setRequestNum(this.requestItemNum[i++]);
				
				req.setManualId(manualId);
				req.setRequestType(StockDirection.getInstance(requestType));
				req.setStockType(StockProductType.getInstance(stockType));
				req.setFromShopId(fromShopId);
				req.setToShopId(toShopId);
				req.setRequestUser(StringUtils.isEmpty(requestUser)?user:requestUser);
				req.setRequestDate(getReqDate());
				req.setRequestCommont(requestCommont);
				req.setStatus(RequestStatus.submit);			}
		}
		
		return li;
		
	}
	
	public Date getReqDate(){
		
		if(StringUtils.isEmpty(requestDate)) return new Date();
		return DateParseUtils.parseDate(requestDate);
	}
}
